home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / HelpWindow.java < prev    next >
Text File  |  1998-11-01  |  3KB  |  125 lines

  1. import java.awt.*;
  2. import java.io.*;
  3. import java.net.*;
  4. import com.sun.java.swing.*;
  5. import com.sun.java.swing.text.*;
  6. import com.sun.java.swing.event.*;
  7.  
  8.  
  9. public class HelpWindow extends com.sun.java.swing.JInternalFrame
  10. {
  11.     public HelpWindow()
  12.     {
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.         //{{INIT_CONTROLS
  19.         setIconifiable(true);
  20.         setMaximizable(true);
  21.         setTitle("Help");
  22.         setResizable(true);
  23.         setClosable(true);
  24.         setDefaultCloseOperation(com.sun.java.swing.JFrame.DISPOSE_ON_CLOSE);
  25.         getContentPane().setLayout(new BorderLayout(0,0));
  26.         setSize(512,400);
  27.         JScrollPane1.setOpaque(true);
  28.         getContentPane().add("Center", JScrollPane1);
  29.         JScrollPane1.setBounds(0,0,512,400);
  30.         JEditorPane1.setEditable(false);
  31.         JScrollPane1.getViewport().add(JEditorPane1);
  32.         JEditorPane1.setBounds(0,0,509,397);
  33.         //}}
  34.         
  35.         try
  36.         {
  37.             File f = new File("HelpFiles/toc.html");
  38.             loadPage("file:"+ f.getAbsolutePath());
  39.         }
  40.         catch(Exception e)
  41.         {
  42.             e.printStackTrace();
  43.         }
  44.     
  45.         //{{REGISTER_LISTENERS
  46.         SymHyperlink lSymHyperlink = new SymHyperlink();
  47.         JEditorPane1.addHyperlinkListener(lSymHyperlink);
  48.         //}}
  49.     }
  50.  
  51.     //{{DECLARE_CONTROLS
  52.     com.sun.java.swing.JScrollPane JScrollPane1 = new com.sun.java.swing.JScrollPane();
  53.     com.sun.java.swing.JEditorPane JEditorPane1 = new com.sun.java.swing.JEditorPane();
  54.     //}}
  55.  
  56.     void loadPage(String page)
  57.     {
  58.         try
  59.         {
  60.             loadPage(new URL(page));
  61.         }
  62.         catch(Exception e)
  63.         {
  64.             e.printStackTrace();
  65.         }
  66.     }
  67.     void loadPage(URL page)
  68.     {
  69.         Cursor c = JEditorPane1.getCursor();
  70.         JEditorPane1.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  71.         SwingUtilities.invokeLater(new PageLoader(page, c));
  72.     }
  73.  
  74.     class SymHyperlink implements com.sun.java.swing.event.HyperlinkListener
  75.     {
  76.         public void hyperlinkUpdate(com.sun.java.swing.event.HyperlinkEvent event)
  77.         {
  78.             Object object = event.getSource();
  79.             if (object == JEditorPane1)
  80.                 jEditorPane1_hyperlinkUpdate(event);
  81.         }
  82.     }
  83.  
  84.     void jEditorPane1_hyperlinkUpdate(com.sun.java.swing.event.HyperlinkEvent event)
  85.     {
  86.         if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
  87.         {
  88.             loadPage(event.getURL());
  89.         }
  90.     }
  91.     class PageLoader implements Runnable
  92.     {
  93.         Cursor origCursor;
  94.         URL url;
  95.         public PageLoader(URL u, Cursor c)
  96.         {
  97.             url=u;
  98.             origCursor = c;
  99.         }
  100.         public void run()
  101.         {
  102.             if(url==null)
  103.             {
  104.                 JEditorPane1.setCursor(origCursor);
  105.                 JEditorPane1.getParent().repaint();
  106.                 return;
  107.             }
  108.             Document doc = JEditorPane1.getDocument();
  109.             try
  110.             {
  111.                 JEditorPane1.setPage(url);
  112.             }
  113.             catch(Exception e)
  114.             {
  115.                 JEditorPane1.setDocument(doc);
  116.                 getToolkit().beep();
  117.             }
  118.             finally
  119.             {
  120.                 url=null;
  121.                 SwingUtilities.invokeLater(this);
  122.             }
  123.         }
  124.     }
  125. }